home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7313 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to get a random string each time??
  5. Date: 14 Feb 1996 15:39:01 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb14083901@qcd.lanl.gov>
  8. References: <4fh5od$qq0@news.nevada.edu> <4fsi8o$4kl@prairie.nodak.edu>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: wstark@prairie.nodak.edu's message of 14 Feb 1996 05:49:44 -0600
  13.  
  14. In article <4fsi8o$4kl@prairie.nodak.edu> wstark@prairie.nodak.edu
  15. (Just Me) writes: 
  16. <snip>
  17.    >   j = rand();
  18.  
  19.    >   while(j>=10)
  20.    >      j=j/10;
  21.  
  22.    I do not understand WHY someone would right code like this.  There are many
  23.  
  24. I will endeavour to give you one possible reason...
  25.  
  26.    other methods of reducing the range of random numbers without resorting to
  27.    a division in a loop (most inefficient).  Here is the most obvious:
  28.  
  29.        j %= 10;
  30.  
  31.    (if you don't understand that, you really need to read a good book on C).
  32.  
  33. Probably because for one reason or the other, the upper bits of the
  34. random number generated were more random than the lower bits.
  35.  
  36. If you do not understand how that _could_ be, you need to read a good
  37. book on random numbers :-) 
  38.  
  39. Cheers
  40. Tanmoy
  41. --
  42. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  43. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  44. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  45. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  46. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  47. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  48.